<!--本页面由uniapp切片工具生成，uni-app切片-可视化设计工具(一套代码编译到7个平台iOS、Android、H5、小程序)，软件下载地址：http://www.ymznkf.com/new_view_669.htm -->
<template>
	<view class="YmContent">
		<view class="info_96">
			<view class="info_61">
				<text decode="true" class="info_62">头像</text>
				<image v-on:click="" :src="user.avatarUrl" mode="scaleToFill" border="0" class="photo">
				</image>
			</view>
			<view class="info_64">
			</view>
			<view class="row4">
				<text decode="true" class="info_66">姓名</text>
				<input class="name" type="text" v-model="user.nickName" />

			</view>
			<view class="info_69">
			</view>
			<view class="row3">
				<text decode="true" class="info_71">地址</text>
				<input class="ids" type="text" v-model="user.address" />
			</view>
			<view class="info_74">
			</view>
			<view class="row2">
				<text decode="true" class="info_76">手机号码</text>
				<input class="mobile" type="text" v-model="user.phone" />
			</view>
			<view class="info_79">
			</view>
			<view class="row1">
				<text decode="true" class="info_81">剩余积分</text>
				<text decode="true" class="job">{{user.integral}}</text>
			</view>
			<view class="info_83">
			</view>
			<button @click="submitMsg()">保存</button>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				user: {},
			}
		},
		onLoad() {
			this.getUser()
			console.log(this.user)
		},
		onShow() {
			console.log("on show");
			//if(this.checkLogin()==false){
			//	return;
			//}

			//执行初始化,需要用的时候，可以把注释取掉
			//this.Refresh("init");
		},
		onPullDownRefresh: function() {
			//下拉刷新的时候请求一次数据
			this.Refresh();
		},

		methods: {
			submitMsg() {
				console.log(this.user)
				let me = this;
				uni.request({
					url: me.serverUrl + `/user/add`,
					data: this.user,
					method: "POST",
					success: (res) => {
						if (res.data.code == '200') {
							uni.showToast({
								title: '修改成功',
								icon: 'success',
								duration: 2000
							});
							uni.removeStorage({
								key: 'user',
								success: function(res) {
									console.log('success');
								}
							});
							uni.setStorage({
								key: 'user',
								data: this.user,
								success: function() {
									console.log(this.user);
								}
							})
							uni.reLaunch({
								url: '/pages/center/center'
							});
						}
					}
				})
			},
			getUser() {
				try {
					this.user = uni.getStorageSync('user');
				} catch (e) {
					// error
				}

			},
		}
	};
</script>

<style lang="scss" scoped>
	@import './info.scss'
</style>